	
  layui.use(['index', 'form', 'laydate'], function(){
    var $ = layui.$
    ,admin = layui.admin
    ,element = layui.element
    ,layer = layui.layer
    ,laydate = layui.laydate;
    var form = layui.form;
  });
  
var index = 1;
function addPackageHtml(){
	var form = layui.form;
	index++;
	if(index>4){
		layer.msg('最多添加4个套餐!',{icon:1,time:1000});
		return;
	}
	var sizehtml = '';
	sizehtml+='<div id="packagediv'+index+'">';
	sizehtml+='<div class="layui-form-item">';
	sizehtml+='<label for="username" class="layui-form-label"><span class="x-red">*</span>套餐'+index+'</label>';
	sizehtml+='<div class="layui-input-inline" style="width: 300px;">';
	sizehtml+='<button class="layui-btn layui-btn-danger layui-btn-sm" onclick="delepePackageHtml('+index+')" type="button"><i class="layui-icon"></i></button>';
	sizehtml+='</div>';
	sizehtml+='</div>';
	sizehtml+='<div class="layui-form-item">';
	sizehtml+='<label for="username" class="layui-form-label"><span class="x-red">*</span>套餐标题</label>';
	sizehtml+='<div class="layui-input-inline" style="width: 300px;">';
	sizehtml+='<input type="text" id="pkgTitle" name="pkgTitle" lay-verify="title" autocomplete="off" placeholder="基础版 10w+18650锂电+USB直充=99元" class="layui-input">';
	sizehtml+='</div>';
	sizehtml+='<label for="username" class="layui-form-label"><span class="x-red">*</span>标题描述</label>';
	sizehtml+='<div class="layui-input-inline" style="width: 500px;">';
	sizehtml+='<input type="text" id="pkgTitleDesc" name="pkgTitleDesc" lay-verify="title" autocomplete="off" placeholder="锋芒毕露，强光远射，小巧便捷，多功能变焦手电筒" class="layui-input">';
	sizehtml+='</div>';
	sizehtml+='</div>';
	sizehtml+='<div class="layui-form-item">';
	sizehtml+='<label for="username" class="layui-form-label"><span class="x-red">*</span>套餐价格</label>';
	sizehtml+='<div class="layui-input-inline" style="width: 300px;">';
	sizehtml+='<input type="text" id="pkgPrice" name="pkgPrice" placeholder="99" autocomplete="off" class="layui-input">';
	sizehtml+='</div>';
	sizehtml+='<label for="username" class="layui-form-label"><span class="x-red">*</span>商品数量</label>';
	sizehtml+='<div class="layui-input-inline" style="width: 500px;">';
	sizehtml+='<select id = "pkgProNum" name="pkgProNum" >';
	sizehtml+='<option selected="selected" value="1">1</option>';
	sizehtml+='<option value="2">2</option>';
	sizehtml+='<option value="3">3</option>';
	sizehtml+='<option value="4">4</option>';
	sizehtml+='<option value="5">5</option>';
	sizehtml+='</select>';
	sizehtml+='</div>';
	sizehtml+='</div>';
	sizehtml+='<div class="layui-form-item">';
	sizehtml+='<label for="username" class="layui-form-label"><span class="x-red">*</span>是否有赠品</label>';
	sizehtml+='<div class="layui-input-inline" style="width: 300px;">';
	sizehtml+='<select id = "pkgProIsGift" name="pkgProIsGift" >';
	sizehtml+='<option selected="selected" value="1">否</option>';
	sizehtml+='<option value="2">有</option>';
	sizehtml+='</select>';
	sizehtml+='</div>';
	sizehtml+='<label for="username" class="layui-form-label"><span class="x-red">*</span>赠送商品</label>';
	sizehtml+='<div class="layui-input-inline" style="width: 500px;">';
	sizehtml+='<select id = "pkgGitPid" name="pkgGitPid" >';
	sizehtml+=getproductList();
	sizehtml+='</select>';
	sizehtml+='</div>';
	sizehtml+='</div>';
	sizehtml+='</div>';
	$("#pdiv").append(sizehtml);
	form.render("select");
}

// 删除套餐 
function delepePackageHtml(num){
	if(num==0){
		layer.msg("必须保留一个套餐",{icon:2,time:1000});
		return;
	}else{
		$("#packagediv"+num).remove();
	}
}

// 拉取所有商品
function getproductList(){
	var phtml="";
	$.ajax({
	    url: $path+'/product/getproductlistByStatus.jhtml',
	    dataType:"json", 
	  	async:false,
	    type: 'POST',
	    success: function (data) {
	    	var rs = eval("("+data+")");
	    	if(rs.data.length>0){
	    		for(var i=0;i<rs.data.length;i++){
	    			phtml+='<option value="'+rs.data[i].proId+'">'+rs.data[i].proTitle+'</option>';
	    		}
	    	}else{
	    		phtml+='<option value="">暂无数据</option>';
	    	}
	    	
	    },
	    error: function (data) {
	        layer.msg("系统异常，请稍后再试",{icon:1,time:1000});
	    }
	}); 
	return phtml;
}

function proSubmit(){
	var layer = layui.layer
	$.ajax({
	    url: $path+'/package/addpackage.jhtml',
	    dataType:"json", 
	  	async:false,
	    type: 'POST',
	    data: $('#pacform').serialize(),
	    success: function (data) {
	    	var rs = eval("("+data+")");
	    	if(rs.code=="error"){
	    		layer.msg(rs.message,{icon:2,time:1000});
	    	}else{
	    		layer.msg(rs.message,{icon:1,time:1000});
	    	}
	    },
	    error: function (data) {
	        layer.msg("系统异常，请稍后再试",{icon:1,time:1000});
	    }
	}); 
}




